package controller;

import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import pojo.Customer;
import service.CustomerManager;
import service.impl.CustomerManagerFactory;

@Controller
public class CustomerController {
	private CustomerManager manager;
	public CustomerController()
	{
		manager=CustomerManagerFactory.getInstance();
	}
	
	@RequestMapping(value="/addCustomer",method=RequestMethod.POST)
	public String addCustomer(Customer c)
	{
		manager.addCustomer(c);
		return "redirect:/listAll";
	}
	
	@RequestMapping(value="/listAll")
	public String findAllCustomer (Model model)
	{
		List<Customer> customers=manager.findAllCustomers();
		model.addAttribute("customers", customers);
		return "Customers_show";
	}
}
